const { createProxyMiddleware } = require("http-proxy-middleware");

module.exports = function (app) {
  app.use(
    "/app/",
    createProxyMiddleware({
      target: "http://47.96.71.171:1000/",
      changeOrigin: true,
      onProxyReq: (proxyReq, req, res) => {
        const fullUrl = `${req.protocol}://${req.get("host")}${
          req.originalUrl
        }`;
        const targetUrl = `${proxyReq.protocol}//${proxyReq.host}${proxyReq.path}`;
        console.log(`Original request: ${req.method} ${fullUrl}`);
        console.log(`Proxied to: ${proxyReq.method} ${targetUrl}`);
      },
      onError: (err, req, res) => {
        console.error("Proxy error:", err);
      },
    })
  );
};
